<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:p="http://primefaces.org/ui"
	template="/templates/template.xhtml">

	<f:metadata>
		<f:event type="preRenderView" listener="#{pesquisarAnimalBean.verificarAcesso}" />
	</f:metadata>

	<ui:define name="body">
		<h:form id="form" prependId="false">
			<p:fieldset legend="#{pesquisarAnimalBean.qualifiedName}" id="fieldPrincipal">

				<h:panelGrid columns="2" columnClasses="coluna20,coluna80" width="100%">
					<h:outputLabel value="Código:" />
					<p:inputText value="#{pesquisarAnimalBean.dto.codigo}" size="5" maxlength="5" />
					<h:outputLabel value="Nome:" />
					<p:inputText value="#{pesquisarAnimalBean.dto.nome}" size="50" maxlength="255" />
					<h:outputLabel value="idade:" />
					<p:inputMask mask="9?99" value="#{pesquisarAnimalBean.dto.idade}" size="5" maxlength="5" />
					<h:outputLabel value="Sexo" />
					<p:selectOneRadio id="optionsSexo" value="#{pesquisarAnimalBean.dto.sexo}">
						<f:selectItem itemLabel="Macho" itemValue="M" />
						<f:selectItem itemLabel="Fêmea" itemValue="F" />
					</p:selectOneRadio>
					<h:outputLabel value="Proprietário:" />
					<p:autoComplete queryDelay="500" value="#{pesquisarAnimalBean.dto.proprietario}" minQueryLength="2"
						id="proprietario" size="50" completeMethod="#{pesquisarAnimalBean.completeProprietario}" forceSelection="true"
						var="proprietario" itemLabel="#{proprietario.nome}" itemValue="#{proprietario.id}"
						converter="proprietarioConverter" />
					<h:outputLabel value="Criador:" />
					<p:autoComplete queryDelay="500" size="50" value="#{pesquisarAnimalBean.dto.proprietarioCriador}"
						minQueryLength="2" id="proprietarioCriador" completeMethod="#{pesquisarAnimalBean.completeCriador}"
						forceSelection="true" var="proprietario" itemLabel="#{proprietario.nome}" itemValue="#{proprietario.id}"
						converter="proprietarioConverter" />

					<h:outputLabel value="Raça:" />
					<p:selectOneMenu id="idRaca" effect="fade" style="width:300px;" value="#{pesquisarAnimalBean.dto.idRaca}">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{pesquisarAnimalBean.listaRaca}" />
					</p:selectOneMenu>

					<h:outputLabel value="Tipo de Animal:" />
					<p:selectOneMenu id="idTipoAnimal" effect="fade" style="width:300px;"
						value="#{pesquisarAnimalBean.dto.idTipoAnimal}">
						<f:selectItem itemLabel="Selecione" itemValue="" />
						<f:selectItems value="#{pesquisarAnimalBean.listaTipoAnimal}" />
					</p:selectOneMenu>
				</h:panelGrid>


				<h:panelGrid columns="4" columnClasses="coluna20,coluna15,coluna2,coluna63" width="100%">

					<h:outputLabel value="Data entrada:" />
					<p:calendar locale="pt" pattern="dd/MM/yyyy" id="dtInicio" navigator="true" maxlength="10" size="15"
						value="${pesquisarAnimalBean.dto.dtInicio}" mode="popup" showOn="button" />
					<h:outputLabel value="a" />
					<p:calendar locale="pt" pattern="dd/MM/yyyy" id="dtFim" navigator="true" maxlength="10" size="15"
						value="${pesquisarAnimalBean.dto.dtFim}" mode="popup" showOn="button" />

				</h:panelGrid>
				<p:toolbar>
					<p:toolbarGroup align="left">
						<p:commandButton value="Limpar" immediate="true" ajax="false" action="pesquisarAnimal.jsf" />
						<p:commandButton value="Pesquisar" ajax="true" process="@form" update="@form"
							action="#{pesquisarAnimalBean.pesquisar}" />
					</p:toolbarGroup>
				</p:toolbar>
				<br />
				<p:dataTable var="lista" id="lista" emptyMessage="#{pesquisarAnimalBean.emptyMessage}" update="lista"
					rowsPerPageTemplate="#{pesquisarAnimalBean.paginacao}" styleClass="coluna100"
					value="#{pesquisarAnimalBean.lazyDataModel}" paginator="true" rows="5"
					rowStyleClass="#{empty rowIx or rowIx mod 2 ne 0 ? 'linhaImpar' : 'linhaPar'}" rowIndexVar="rowIx">

					<p:column headerText="Nome" style="width:20%">
						<h:outputLabel value="#{lista.nome}" />
					</p:column>
					<p:column headerText="Sexo" style="width:10%">
						<h:outputText value="#{lista.sexoFormat}" />
					</p:column>
					<p:column headerText="Proprietário" style="width:20%">
						<h:outputLabel value="#{lista.proprietario.nome}" />
					</p:column>
					<p:column headerText="Raça" style="width:15%">
						<h:outputText value="#{lista.raca.descricao}" />
					</p:column>
					<p:column headerText="Tipo Animal" style="width:10%">
						<h:outputText value="#{lista.tipoAnimal.descricao}" />
					</p:column>
					<p:column headerText="Entrada" style="width:5%">
						<h:outputLabel value="#{lista.dtEntrada}">
							<f:convertDateTime pattern="dd/MM/yyyy" />
						</h:outputLabel>
					</p:column>

					<p:column headerText="Ação" style="width:5%;text-align:center;">
						<p:commandLink title="Visualizar" style="padding:5px !important;" update="@form" process="@this"
							oncomplete="animalDialog.show()" action="#{pesquisarAnimalBean.loadSelect}">
							<h:graphicImage library="design/imagem" name="icone-visualizar.png" />
							<f:setPropertyActionListener target="#{pesquisarAnimalBean.animalSelect}" value="#{lista}" />
						</p:commandLink>
					</p:column>
				</p:dataTable>

				<p:dialog appendToBody="false" header="Informações Animal" id="dlgAnimal" widgetVar="animalDialog" resizable="false"
					width="650" height="520" showEffect="explode" hideEffect="explode">
					<p:toolbar>
						<p:toolbarGroup align="left">
							<p:commandButton rendered="#{p:ifGranted('ROLE_ANIMAL_EDITAR') or p:ifGranted('ROLE_PES_ANIMAL_EDITAR')}"
								value="Alterar" title="Alterar" action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="animal.jsf" />
							</p:commandButton>
							<p:commandButton rendered="#{p:ifGranted('ROLE_FOTO')}" value="Foto" title="Foto"
								action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="imagemAnimal.jsf" />
							</p:commandButton>
							<p:commandButton rendered="#{p:ifGranted('ROLE_AVALIACAO')}" value="Avaliação"
								action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="avaliacaoAnimal.jsf" />
							</p:commandButton>
							<p:commandButton rendered="#{p:ifGranted('ROLE_MEDICAO')}" value="Medição"
								action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="medicaoAnimal.jsf" />
							</p:commandButton>
							<p:commandButton
								rendered="#{p:ifGranted('ROLE_DOADORA') and pesquisarAnimalBean.animalSelect.tipoAnimal.id eq 1}"
								value="Doadora" action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="doadora.jsf" />
							</p:commandButton>
							<p:commandButton
								rendered="#{p:ifGranted('ROLE_REPRO_F') and pesquisarAnimalBean.animalSelect.tipoAnimal.id eq 2}"
								value="Reprodução" action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="controleReproducaoF.jsf" />
							</p:commandButton>
							<p:commandButton
								rendered="#{p:ifGranted('ROLE_REPRO_M') and pesquisarAnimalBean.animalSelect.tipoAnimal.id eq 3}"
								value="Reprodução" action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="controleReproducaoM.jsf" />
							</p:commandButton>
							<p:commandButton rendered="#{p:ifGranted('ROLE_MATRIZ') and pesquisarAnimalBean.animalSelect.tipoAnimal.id eq 4}"
								value="Matriz" action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="matriz.jsf" />
							</p:commandButton>
							<p:commandButton rendered="#{p:ifGranted('ROLE_MANEJO')}" value="Manejo"
								action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="manejoExibicao.jsf" />
							</p:commandButton>
							<p:commandButton rendered="#{p:ifGranted('ROLE_MOVIMENTACAO')}" value="Movimentação"
								action="#{pesquisarAnimalBean.encaminhar}">
								<f:setPropertyActionListener target="#{pesquisarAnimalBean.pagina}" value="movimentacao.jsf" />
							</p:commandButton>
						</p:toolbarGroup>
					</p:toolbar>
					<br />
					<h:panelGrid id="display" columns="1" width="100%">
						<f:facet name="header">
							<h:panelGrid columns="1" width="100%" id="imagemPanel">
								<p:toolbar rendered="#{!empty pesquisarAnimalBean.animalSelect.listaUrls}" style="width: 250px; height: 180px;">
									<p:toolbarGroup>
										<h:panelGrid columns="2" width="5%">
											<p:commandButton type="button" onclick="switcher.previous();" icon="ui-icon-circle-triangle-w" />
											<p:commandButton type="button" onclick="switcher.next();" icon="ui-icon-circle-triangle-e" />
										</h:panelGrid>
										<p:imageSwitch effect="shuffle" widgetVar="switcher" slideshowSpeed="6000" slideshowAuto="true">
											<ui:repeat value="#{pesquisarAnimalBean.animalSelect.listaUrls}" var="image">
												<p:graphicImage value="/imagemServlet?file=#{image}" style="width: 250px; height: 150px;" />

											</ui:repeat>
										</p:imageSwitch>
									</p:toolbarGroup>
								</p:toolbar>
							</h:panelGrid>
						</f:facet>
						<h:panelGrid columns="4" id="panelExibicao" columnClasses="coluna20,coluna30,coluna25,coluna25" width="100%">
							<h:outputText value="Código:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.codigo}" />

							<h:outputText value="Nome:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.nome}" id="nome" />

							<h:outputLabel value="Idade:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.idade}" />

							<h:outputLabel value="Sexo:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.sexoFormat}" />

							<h:outputLabel value="Parto(s):" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.qtdParto}" />

							<h:outputLabel value="Embrião Efetivado:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.qtdEmbriaoEfetivado}" />

							<h:outputLabel value="aborto(s):" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.qtdAborto}" />

							<h:outputLabel value="Embrião Não Efetivado:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.qtdEmbriaoNaoEfetivado}" />

							<h:outputLabel value="Proprietário:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.proprietario.nome}" />

							<h:outputLabel value="Criador:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.proprietarioCriador.nome}" />

							<h:outputLabel value="Pai:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.pai.nome}" />

							<h:outputLabel value="Mãe:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.mae.nome}" />

							<h:outputLabel value="Data de Entrada:" />
							<h:outputLabel value="#{pesquisarAnimalBean.animalSelect.dtEntrada}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputLabel>

							<h:outputLabel value="Data de Saída:" />
							<h:outputLabel value="#{pesquisarAnimalBean.animalSelect.dtSaida}">
								<f:convertDateTime pattern="dd/MM/yyyy" />
							</h:outputLabel>
							<h:outputLabel value="Pelagem:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.pelagem.descricao}" />

							<h:outputLabel value="Situação:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.movimentacaoAnimalAtual.situacao.descricao}" />

							<h:outputLabel value="Função do Animal:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.funcaoAnimal.descricao}" />

							<h:outputLabel value="Tipo de Animal:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.tipoAnimal.descricao}" />

							<h:outputLabel value="Raça:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.raca.descricao}" />

							<h:outputLabel value="Grau de Sangue:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.grauSangue.descricao}" />

							<h:outputLabel value="Tipo De Cobertura:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.tipoCobertura.descricao}" />

							<h:outputLabel value="Observação:" />
							<h:outputText value="#{pesquisarAnimalBean.animalSelect.observacao}" />
						</h:panelGrid>
					</h:panelGrid>

				</p:dialog>

			</p:fieldset>
		</h:form>
	</ui:define>
</ui:composition>